*** Stata 14.1 reproduction code for Mader & Schoen. 2017. Ideological voting in context: The case of Germany during the Merkel era

*** This code (1) recodes public opinion data and (2) and reproduces all results reported in Mader & Schoen (2017).

*** Data sets used:
	*GLES Long-term Online-Tracking, Cumulation 2009-2014 (T6, T8-T24), Core questions (ZA5749, version 1.0)
	*GLES Online Tracking T01 (ZA5334, version 3.0)
	*GLES Online Tracking T02 (ZA5335, version 4.0)
	*GLES Online Tracking T03 (ZA5336, version 4.0)
	*GLES Online Tracking T04 (ZA5337, version 3.0)
	*GLES Online Tracking T05 (ZA5338, version 3.0)
	*GLES Online Tracking T07 (ZA5340, version 4.0)
	*GLES Online Tracking T25 (ZA5725, version 1.0)
	*GLES Online Tracking T26 (ZA5726, version 1.0)
	*GLES Online Tracking T27 (ZA5727, version 1.0)
	*GLES Online Tracking T28 (ZA5728, version 1.0)
	*GLES Online Tracking T29 (ZA5729, version 1.0)
	*GLES Online Tracking T30 (ZA5730, version 1.2)
	
	*GLES Long-Term Media Data Analysis recode (see Stata code "Mader_Schoen_2017_syntax_1.do")
	
*** All data sets are publicly available at gesis.org.

*** Run "Mader_Schoen_2017_reproduction_syntax_1.do" first

*****************************************************************************************************************
*****************************************************************************************************************
													*(1) Clean public opinion data
*****************************************************************************************************************
*****************************************************************************************************************

	set more off

** Define directory with data sets
	cd "specify folder with data sets"

** Open data set GLES Long-term Online-Tracking, Cumulation 2009-2014 (T6, T8-T24), Core questions (ZA5749, version 1.0)
	use "ZA5749_v1-0-0", clear

	
*intended vote choice (second vote)
	fre k0080ba_1
	gen vote = 1 if k0080ba_1 == 1 | k0080ba_1 == 2
	replace vote = 4 if k0080ba_1 == 4
	replace vote = 5 if k0080ba_1 == 5
	replace vote = 6 if k0080ba_1 == 6
	replace vote = 7 if k0080ba_1 == 7
	replace vote = 11 if k0080ba_1 == 801 | k0080ba_1 == 215 | k0080ba_1 == 322 | k0080ba_1 == 206
	tab k0080ba_1 vote, mis
	

*Left-right self-placement
	fre k0240_1 
	mvdecode k0240_1 , mv(-98 -99 = .)
	gen lire = (k0240_1 - 1) / 10
	tab lire, mis
	
*Party identificaion
	fre k0490a_1
	mvdecode k0490a_1, mv (-99 -98 = .)
	gen pid = 1 if k0490a_1 == 1 | k0490a_1 == 2 | k0490a_1 == 3
	replace pid = 4 if k0490a_1 == 4
	replace pid = 5 if k0490a_1 == 5
	replace pid = 6 if k0490a_1 == 6
	replace pid = 7 if k0490a_1 == 7
	replace pid = 11 if k0490a_1 == 801 | k0490a_1 == 322 | k0490a_1 == 215 | k0490a_1 == 206
	replace pid = 13 if k0490a_1 == 808
	tab k0490a_1 pid, mis
		
*ID variable which identifies Online Trackings
	gen track = survey
*Define missiongs for Tracking specific #id variables 
	mvdecode lfdn_T6 lfdn_T8 lfdn_T9 lfdn_T10 lfdn_T11 lfdn_T12 lfdn_T13 lfdn_T14 lfdn_T15 lfdn_T16 lfdn_T17 lfdn_T18 lfdn_T19 lfdn_T20 lfdn_T21 lfdn_T22 lfdn_T23 lfdn_T24, mv(-97 = .)
	recast float lfdn_T6 lfdn_T8 lfdn_T9 lfdn_T10 lfdn_T11 lfdn_T12 lfdn_T13 lfdn_T14 lfdn_T15 lfdn_T16 lfdn_T17 lfdn_T18 lfdn_T19 lfdn_T20 lfdn_T21 lfdn_T22 lfdn_T23 lfdn_T24
	
*Weight
	 gen weight1 = wei_mzoz //
			
*Political involvement
	fre k0050_1
	recode k0050_1 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0), gen(polint)
	tab k0050_1 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1
	
*Age
	fre k0020_1
	
	gen age = 0
	replace age = year - k0020_1
	replace age = . if age == 2108
	
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60
	
	fre age_cat

*Education
	fre k0030_1
	gen edu = 1 if k0030_1 == 1 | k0030_1 == 2
	replace edu = 2 if k0030_1 == 3 
	replace edu = 3 if k0030_1 == 4 | k0030_1 == 5
	replace edu = . if k0030_1 == 6
		
*Gender 
	gen female = 0 if k0010_1 == 1
	replace female = 1 if k0010_1 ==2
		
*Region
	fre k0040_1
	recode k0040_1 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1) (-99 = .), gen(ost)
	
*Keep only relevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save data set	
	save "kum_t06_t24.dta", replace	
	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T01
	use "ZA5334_v3-0-0", clear

*Intended vote choice (Zweitstimme)
	fre a08a
	gen vote = 1 if a08a == 1
	replace vote = 4 if a08a == 4
	replace vote = 5 if a08a == 5
	replace vote = 6 if a08a == 6
	replace vote = 7 if a08a == 7
	replace vote = 11 if a08a == 801
	tab a08a vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 1
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 801 | a36c == 215
	replace pid = 13 if a36 == 808
	tab a36 pid, mis

*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 1
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 3 | v_03 == 4
	
*Gender
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre Buland
	gen ost = 1 if Buland == 4 |  Buland == 8 | Buland == 13 | Buland == 14 | Buland == 16
	replace ost = 0 if Buland == 1 | Buland == 2 | Buland == 3 | Buland == 5 | Buland == 6 | Buland == 7 | Buland == 9 | Buland == 10 | Buland == 11 | Buland == 12 | Buland == 15 
	
*ID variable which identifies Online Trackings
	gen track = 1

*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1
	
*weights
	gen weight1 = gew1_t1 // Gewichtung T1 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t01.dta", replace	
	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T02
	use "ZA5335_v4-0-0", clear

*Intended vote choice (Zweitstimme
	fre a08a
	gen vote = 1 if a08a == 1
	replace vote = 4 if a08a == 4
	replace vote = 5 if a08a == 5
	replace vote = 6 if a08a == 6
	replace vote = 7 if a08a == 7
	replace vote = 11 if a08a == 801
	tab a08a vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 1
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 801
	replace pid = 13 if a36 == 808
	tab a36 pid, mis

*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 1
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 3 | v_03 == 4
	
*Gender
	fre v_01
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre v_04
	recode v_04 (1 2 3 5 6 7 9 10 11 12 15 = 0) (4 8 13 14 16 = 1), gen(ost)
	
*ID variable which identifies Online Trackings
	gen track = 2
	
*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = gew1_T2 // Gewichtung T2 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t02.dta", replace	
		
********************************************************************************************************************		
** Open data set: GLES Online Tracking T03
	use "ZA5336_v4-0-0", clear

*Intended vote choice (Zweitstimme
	fre a08a
	gen vote = 1 if a08a == 1
	replace vote = 4 if a08a == 4
	replace vote = 5 if a08a == 5
	replace vote = 6 if a08a == 6
	replace vote = 7 if a08a == 7
	replace vote = 11 if a08a == 8
	tab a08a vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 1
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 8
	replace pid = 13 if a36 == 84
	tab a36 pid, mis

*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 1
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 3 | v_03 == 4
	
*Gender
	fre v_01
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre Buland
	recode Buland (1 2 3 5 6 7 9 10 11 12 15 = 0) (4 8 13 14 16 = 1) (99 = .), gen(ost) 
	
*ID variable which identifies Online Trackings
	gen track = 3
	
*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weights
	gen weight1 = gew1_t3 // Gewichtung T3 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t03.dta", replace	

********************************************************************************************************************		
** Open data set: GLES Online Tracking T04
	use "ZA5337_v3-0-0", clear

*Intended vote choice (Zweitstimme
	fre a08a
	gen vote = 1 if a08a == 1
	replace vote = 4 if a08a == 4
	replace vote = 5 if a08a == 5
	replace vote = 6 if a08a == 6
	replace vote = 7 if a08a == 7
	replace vote = 11 if a08a == 8
	tab a08a vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 1
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 8
	replace pid = 13 if a36 == 84
	tab a36 pid, mis
	
*ID variable which identifies Online Trackings
	gen track = 4

*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 1
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 3 | v_03 == 4
	
*Gender
	fre v_01
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre Buland
	recode Buland (1 2 3 5 6 7 9 10 11 12 15 = 0) (4 8 13 14 16 = 1) (100 = .), gen(ost)

*Weights
	gen weight1 = gew1_t4 // Gewichtung T4 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t04.dta", replace	
	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T05
	use "ZA5338_v3-0-0", clear

*Intended vote choice (Zweitstimme
	fre a08a
	gen vote = 1 if a08a == 1
	replace vote = 4 if a08a == 4
	replace vote = 5 if a08a == 5
	replace vote = 6 if a08a == 6
	replace vote = 7 if a08a == 7
	replace vote = 11 if a08a == 8
	tab a08a vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 1
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 8
	replace pid = 13 if a36 == 84
	tab a36 pid, mis

*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 1
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 3 | v_03 == 4
	
*Gender
	fre v_01
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre v_04c
	recode v_04c (1 2 3 5 6 7 9 10 11 12 15 17 18 = 0) (4 8 13 14 16 = 1), gen(ost)

*ID variable which identifies Online Trackings
	gen track = 5
	
*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weights
	gen weight1 = gew1_t5 // Gewichtung T5 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t05.dta", replace	

	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T07
	use "ZA5340_v4-0-0", clear

*Recall vote choice BTW 2013 (Zweitstimme)
	fre T7_04b
	gen vote = 1 if T7_04b == 1
	replace vote = 4 if T7_04b == 4
	replace vote = 5 if T7_04b == 5
	replace vote = 6 if T7_04b == 6
	replace vote = 7 if T7_04b == 7
	replace vote = 11 if T7_04b == 801
	tab T7_04b vote, mis
	
*Left-right self-placement
	fre a33 
	mvdecode a33 , mv(98 99 = .)
	gen lire = (a33  - 1) / 10
	tab lire a33 , mis
	
*Party identification
	fre a36
	mvdecode a36, mv (998 999 = .)
	gen pid = 1 if a36 == 2
	replace pid = 1 if a36 == 3
	replace pid = 4 if a36 == 4
	replace pid = 5 if a36 == 5
	replace pid = 6 if a36 == 6
	replace pid = 7 if a36 == 7
	replace pid = 11 if a36 == 801
	replace pid = 13 if a36 == 808
	tab a36 pid, mis
	
*Age
	fre v_02
	gen age_cat = v_02

*Education
	fre v_03
	gen edu = .
	replace edu = 3 if v_03 == 5 | v_03 == 4
	replace edu = 2 if v_03 == 3 
	replace edu = 1 if v_03 == 1 | v_03 == 2
	replace edu = . if v_03 == 6
	
*Gender
	fre v_01
	gen female = 0 if v_01 == 1
	replace female = 1 if v_01 ==2
	
*State of residence
	fre T7_01
	recode T7_01 (1 2 3 5 6 7 9 10 11 12 15 = 0) (4 8 13 14 16 = 1), gen(ost)
	
*ID variable which identifies Online Trackings
	gen track = 7
	
*Political involvement
	fre a01
	recode a01 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab a01 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weights
	gen weight1 = gew1_t71 // Gewichtung T5 (Anpassung an Mikrozensus)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t07.dta", replace	
	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T25
	use "ZA5725_v1-0-0", clear

*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322
	replace pid = 13 if t46a == 808 
	tab t46a pid, mis
	
*Age
	fre t2
	gen age = 2014 - t2 
		
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
	
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)
	
*ID variable which identifies Online Trackings
	gen track = 25
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, ohne Zeitunterschreitern)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost

*Save new data set	
	save "t25.dta", replace		

********************************************************************************************************************		
** Open data set: GLES Online Tracking T26
	use "ZA5726_v1-0-0", clear

*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322
	replace pid = 13 if t46a == 808 
	tab t46a pid
	
*Age
	fre t2
	gen age = 2014 - t2 

	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
	
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)

*Employment
	fre t52
	recode t52 (-99=.), gen(employm)
	
*ID variable which identifies Online Trackings
	gen track = 26
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (-99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, o. Zeitunterschreiter)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t26.dta", replace		
	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T27
	use "ZA5727_v1-0-0", clear
	

*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322 | t46a == 206
	replace pid = 13 if t46a == 808 
	tab t46a pid
	
*Age
	fre t2
	gen age = 2015 - t2
	
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
		
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)

*ID variable which identifies Online Trackings
	gen track = 27
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (-99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, o. Zeitunterschreiter)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t27.dta", replace		


********************************************************************************************************************		
** Open data set: GLES Online Tracking T28
	use "ZA5728_v1-0-0", clear
	
*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322 | t46a == 206
	replace pid = 13 if t46a == 808 
	tab t46a pid
	
*Age
	fre t2
	gen age = 2015 - t2
	
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
		
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)

*ID variable which identifies Online Trackings
	gen track = 28
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (-99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, o. Zeitunterschreiter)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t28.dta", replace	
	

********************************************************************************************************************		
** Open data set: GLES Online Tracking T29
	use "ZA5729_v1-0-0", clear
	
*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322 | t46a == 206
	replace pid = 13 if t46a == 808 
	tab t46a pid
	
*Age
	fre t2
	gen age = 2015 - t2
	
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
		
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)
	
*ID variable which identifies Online Trackings
	gen track = 29
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (-99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, o. Zeitunterschreiter)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t29.dta", replace	

	
********************************************************************************************************************		
** Open data set: GLES Online Tracking T30
	use "ZA5730_v1-2-0", clear
	
*Intended vote choice (Zweitstimme)
	fre t8ba
	gen vote = 1 if t8ba == 1
	replace vote = 4 if t8ba == 4
	replace vote = 5 if t8ba == 5
	replace vote = 6 if t8ba == 6
	replace vote = 7 if t8ba == 7
	replace vote = 11 if t8ba == 801 | t8ba == 215 | t8ba == 322 | t8ba == 206  | t8ba == 800  
	tab t8ba vote, mis
	
*Left-right self-placement
	fre t24 
	mvdecode t24 , mv(-98 -99 = .)
	gen lire = (t24  - 1) / 10
	tab lire t24 , mis
	
*Party identification
	fre t46a
	mvdecode t46a, mv (-99 -98 = .)
	gen pid = 1 if t46a == 2
	replace pid = 1 if t46a == 3
	replace pid = 4 if t46a == 4
	replace pid = 5 if t46a == 5
	replace pid = 6 if t46a == 6
	replace pid = 7 if t46a == 7
	replace pid = 11 if t46a == 801 | t46a == 215 | t46a == 322 | t46a == 206 | t46a == 800
	replace pid = 13 if t46a == 808 
	tab t46a pid
	
*Age
	fre t2
	gen age = 2015 - t2
	
	gen age_cat = .
	replace age_cat = 1 if age < 30
	replace age_cat = 2 if age >= 30 & age < 40
	replace age_cat = 3 if age >= 40 & age < 50
	replace age_cat = 4 if age >= 50 & age < 60
	replace age_cat = 5 if age >= 60

*Education
	fre t3
	gen edu = .
	replace edu = 3 if t3 == 7 | t3 == 8
	replace edu = 2 if t3 == 5 | t3 == 6
	replace edu = 1 if t3 == 1 | t3 == 2 | t3 == 3 | t3 == 4
	replace edu = . if t3 == 9
	
*Gender
	fre t1
	gen female = 0 if t1 == 1
	replace female = 1 if t1 ==2
		
*State of residence
	fre t4
	recode t4 (1 2 3 4 5 6 7 8 9 10 11 = 0) (12 13 14 15 16 = 1), gen(ost)
	
*ID variable which identifies Online Trackings
	gen track = 30
	
*Political involvement
	fre t5
	recode t5 (1 = 1)(2 = .75)(3 = .5) (4 = .25)(5 = 0) (-99 = .), gen(polint)
	tab t5 polint, mis	
		
	gen polint_d = 0
	replace polint_d = 1 if polint == .75 | polint == 1

*Weight
	gen weight1 = wei_mzoz // Sozial-/regionalstrukturelles Gewicht(MZ2012, o. Zeitunterschreiter)

*Drop irrelevant variables
	keep vote lire pid track weight1 polint polint_d age age_cat edu female ost
	
*Save new data set	
	save "t30.dta", replace	
	
*********************************************************************************************************************
**Cumulation of GLES Online Tracking waves T01 - T30
		use "kum_t06_t24.dta", clear
		append using "t01.dta"
		append using "t02.dta"
		append using "t03.dta"
		append using "t04.dta"
		append using "t05.dta"
		append using "t07.dta"
		append using "t25.dta"
		append using "t26.dta"
		append using "t27.dta"
		append using "t28.dta"
		append using "t29.dta"
		append using "t30.dta"
			
*********************************************************************************************************************
**Labeling and Recoding
	
*edu
	label var edu "Education"
	label define edu_lab 1 "low level of education" 2 "middle level of education" 3 "high level of education"
	label value edu edu_lab
			
*female
	label var female "Gender"
	label define female_lab 1 "female" 0 "male"
	label value female female_lab

*ost
	lab var ost "Origin"
	label define ost_lab 1 "ost" 0 "west"
	labe value ost ost_lab
		
*Age
	lab var age "Age, categorized"
	label define age_lab 1 "18 to 29" 2 "30 to 39" 3 "40 to 49" 4 "50 to 59 " 5 " > 60"
	labe value age_cat age_lab		
		
*Operationalization of "the elderly"
	gen above50 = .
	replace above50 = 0 if age <= 50 & age > 17
	replace above50 = 1 if age > 50 & age < 113
	tab track above50
	
*Vote intention
	label var vote "Vote Intention"
	label define votescalo ///
	1 "CDU/CSU" ///
	4 "SPD" ///
	5 "FDP" ///
	6 "Die Gruenen" ///
	7 "Die Linke" ///
	11 "andere Parteien"
	label values vote votescalo
	fre vote

*Vote intention dummies
	gen v_union = 0
	replace v_union = 1 if vote == 1 | vote == 2
	label var v_union "CDU/CSU vote"	
	tab vote v_union
	
	gen v_spd = 0
	replace v_spd = 1 if vote == 4
	label var v_spd "SPD vote"
	
	gen v_fdp = 0
	replace v_fdp = 1 if vote == 5
	label var v_fdp "FDP vote"	

	gen v_greens = 0
	replace v_greens = 1 if vote == 6
	label var v_greens "Greens vote"		
			
	gen v_left = 0
	replace v_left = 1 if vote == 7
	label var v_left "Left vote"	

	gen v_camps = .
	replace v_camps = 1 if vote == 1 | vote == 5  | vote == 9
	replace v_camps = 0 if vote == 4 | vote == 6  | vote == 7  | vote == 8
	label var v_camp "vote for left or right camp"
	label define v_camp_lab ///
		0 "vote for left camp (SPD/GREENS/Left/Pirates)" ///
		1 "vote for right camp (Union/FDP(AFD)"
	label values v_camp v_camp_lab			
	
		
*Left-right self-placement
	label var lire "Left-right self-placement"
	label define lire_lab ///
		0 "Left" ///
		1 "Right"
	label values lire lire_lab
			
*Split left-right self-placement
	recode lire (.5 .6 .7 .8 .9 1 = 0) (.4 = .2) (.3 = .4) (.2 = .6) (.1 = .8) (0 = 1), gen(li)
	lab var li "Self-placement on left wing"
	label define li_lab ///
		0 "Middle or Right" ///
		1 "Left"
	label values li li_lab

	recode lire (.5 .4 .3 .2 .1 0 = 0) (.6 = .2) (.7 = .4) (.8 = .6) (.9 = .8) (1 = 1), gen(re)
	lab var re "Self-placement on right wing"
	label define re_lab ///
		0 "Middle or Left" ///
		1 "Right"
	label values re re_lab 

	recode lire (.4 .5 .6 .7 .8 .9 1 = 0) (.3 = .25) (.2 = .5) (.3 = .75)  (0 = 1), gen(li2)
	lab var li "Self-placement on left wing"
	label values li2 li_lab

	recode lire (.6 .5 .4 .3 .2 .1 0 = 0) (.7 = .25) (.8 = .5) (.9 = .75) (1 = 1), gen(re2)
	lab var re "Self-placement on right wing"
	label values re2 re_lab 
			
*Missing value for lire
	gen liremis = 0
	replace liremis = 1 if lire == .
	label var liremis "Missing values for left-right self-placement"
	label define liremis_lab ///
		0 "no missing value" ///
		1 "missing values"
	label values liremis liremis_lab	
	
*PID
	label var pid "Party identification"
	label define pidlab ///
		1 "CDU/CSU" ///
		4 "SPD" ///
		5 "FDP" ///
		6 "Die Gruenen" ///
		7 "Die Linke" ///
		11 "andere Parteien" ///
		13 "keine Partei"
	label values pid pidlab
	fre pid
			
	gen pi5 = 0
	replace pi5 = 1 if pid == 1
	replace pi5 = 2 if pid == 4
	replace pi5 = 3 if pid == 5
	replace pi5 = 4 if pid == 6
	replace pi5 = 5 if pid == 7
	label var pi5 "Party identification"
	label define lab_pi5 0 "No/other PI or missing value" 1 "PI CDU/CSU" 2 "PI SPD" 3 "PI FDP" 4 "PI Greens" 5 "PI Left"
	label value pi5 lab_pi5
	fre pi5
	
	tab pi5, gen(pid)

	gen nopi = 0
	replace nopi = 1 if pid == 13
	label var nopi "Dummy: No party identification"
	label define lab_nopi 0 "Some PI or missing value" 1 "No PI"
	label value nopi lab_nopi
		
*Political involvement
	label var polint "Political involvement"
	label define lab_polint 0 "low involvement" 1 "high involvement"
	label value polint lab_polint

	label var polint_d "Dummy: High political involvement"
	label value polint_d lab_polint

*Center level 1 variables at their within-cluster mean
	egen liremeans = mean(lire), by(track)
	gen wcm_lire = lire - liremeans
	
	egen limeans = mean(li), by(track)
	gen wcm_li = li - limeans

	egen remeans = mean(re), by(track)
	gen wcm_re = re - remeans
		
*ID variable for Tracking 8-30 (For T08-T30, media data are available)
	gen track830 = track
	recode track830 (1 2 3 4 5 6 7 = .)

	label var track830  "Trackings 8-22"
	label define track830_lab ///
		8 "Dec-09 (T8)" 9 "Mar-10 (T9)" 10 "Jun-10 (T10)" 11 "Sep-10 (T11)" 12 "Dec-10 (T12)" 13 "Mar-11 (T13)" ///
		14 "May-11 (T14)" 15 "Aug-11 (T15)" 16 "Dec-11 (T16)" 17 "May-12 (T17)" 18 "Sep-12 (T18)" 19 "Jan-13 (T19)" 20 "May-13 (T20)" ///
		21 "Sep-13 (T21)" 22 "Nov-13 (T22)" ///
		23 "Jan-14 (13)" 24 "May-14 (14)" 25 "Aug-14 (T25)" 26 "Nov-14 (T26)" 27 "Feb-15 (T27)" 28 "Jun-15 (T28)" 29 "Sep-15 (T29)" 30 "Dec-15 (T30)"
	label value track830 track830_lab
	fre track830

	gen track022 = track830 - 8
		
*ID variable for level 2 variables	(Dummy variable to pick one obervation per level 2 observation)
		egen pickone = tag(track) 

		
*ID variables to identify problematic Trackings (when empty cells in IV-DV data matrix prohibit estimation of effects)

	*Left identifier voting for CDU/CSU in Tracking 4 (Figure 3)
	gen help0 = 0 
	replace help0 = 1 if track == 4

	*Right identifier voting for SPD in Tracking 27, 28 (Online Supplement, Figure A2)
	gen help1 = 0
	replace help1 = 1 if track == 27 | track == 28 
	
	*Left identifier voting for Greens in T25 and right identifier in Tracking 2, 26 (Online Supplement, Figure A3)
	gen help2 = 0
	replace help2 = 1 if track == 25
	
	gen help3 = 0
	replace help3 = 1 if track == 2 | track == 26 
	
	*Right identifier voting for Left in T17, 18, 20, 22, 24 (Online Supplement, Figure A4)
	gen help4 = 0
	replace help4 = 1 if  track == 17 | track == 18 | track == 20 | track == 22 | track == 24

	
*****************************************************************************************************************
*****************************************************************************************************************
													* (2) Merge public opinion and media data
*****************************************************************************************************************
*****************************************************************************************************************
*Merge Trackings and media content data
	merge m:1 track using "medien_aggr.dta"
	
********************************************************************************************************************
*Save as new data set
	save "GLES_tracking_media.dta", replace
